package com.jy.adscm.operation.cg.service.impl;

import com.baomidou.mybatisplus.enums.SqlLike;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.cg.bean.*;
import com.jy.adscm.operation.cg.mapper.mysql.CgMaterialMapper;
import com.jy.adscm.operation.cg.mapper.mysql.JqPlanMapper;
import com.jy.adscm.operation.cg.service.JqPlanService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.operation.cg.service.MachineProcessService;
import com.jy.adscm.operation.mscyb.bean.*;
import com.jy.adscm.operation.mscyb.mapper.mysql.*;
import com.jy.adscm.operation.mscyb.service.*;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import com.jy.adscm.zltx.bean.JyDrawingType;
import com.jy.adscm.zltx.mapper.mysql.JyDrawingTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2019-07-26
 */
@Service
public class JqPlanServiceImpl extends ServiceImpl<JqPlanMapper, JqPlan> implements JqPlanService {
    @Autowired
    JyUserMapper jyUserMapper;
    @Autowired
    JqbzSettingsMapper jqbzSettingsMapper;
    @Autowired
    JqzzSettingMapper jqzzSettingMapper;
    @Autowired
    JqcsSettingMapper jqcsSettingMapper;
    @Autowired
    JqdbSettingsMapper jqdbSettingsMapper;
    @Autowired
    JqbzPartsassemblyService jqbzPartsassemblyService;
    @Autowired
    JqzzMachineService jqzzMachineService;
    @Autowired
    JqcsMachineTestService jqcsMachineTestService;
    @Autowired
    JqfzSettingMapper jqfzSettingMapper;
    @Autowired
    JqfzIssueQsService jqfzIssueQsService;
    @Autowired
    JqdbMachinepackingService  jqdbMachinepackingService;
    @Autowired
    MachineProcessService machineProcessService;
    @Autowired
    JqzzMachineMapper jqzzMachineMapper;
    @Autowired
    JyDrawingTypeMapper jyDrawingTypeMapper;
    @Autowired
    JqzzSettingInputMapper  jqzzSettingInputMapper;
    @Autowired
    CgMaterialMapper cgMaterialMapper;
    @Autowired
    JqzzMaterialMapper jqzzMaterialMapper;
    @Autowired
    JqzzSettingPartsMapper jqzzSettingPartsMapper;
    @Autowired
    JqzzPartsMaterialMapper jqzzPartsMaterialMapper;
    @Autowired
    JqzzSettingProcessMapper jqzzSettingProcessMapper;
    @Autowired
    JqzzAssemblyMapper jqzzAssemblyMapper;

    @Override
    public Page<JqPlan> selectJqPlan(Page<JqPlan> page, QueryJqPlan queryJqPlan) {
        Wrapper<JqPlan> wrapper =new EntityWrapper<>();
        if (AdscmBaseUtils.getInstance().isNotEmpty(queryJqPlan.getMakeNo(),null)){
            wrapper.like("makeNo",queryJqPlan.getMakeNo());
        }
        if (AdscmBaseUtils.getInstance().isNotEmpty(queryJqPlan.getGid(),null)){
            wrapper.eq("gid",queryJqPlan.getGid());
        }
        page = super.selectPage(page, wrapper);
        List<JqPlan> jqPlans = page.getRecords();
        for (JqPlan jqPlan : jqPlans) {
            if (AdscmBaseUtils.getInstance().isNotEmpty(jqPlan.getCreator(),null)){
                JyUser jyUser = jyUserMapper.selectById(jqPlan.getCreator());
                jqPlan.setCreatorName(jyUser.getName());
            }
            if (AdscmBaseUtils.getInstance().isNotEmpty(jqPlan.getPerfromer(),null)){
                JyUser jyUser = jyUserMapper.selectById(jqPlan.getPerfromer());
                jqPlan.setPerfromerName(jyUser.getName());
            }
            if (AdscmBaseUtils.getInstance().isNotEmpty(jqPlan.getGid(),null)){
                if ("1".equals(jqPlan.getGxType())){
                    JqbzSettings jqbzSettings = jqbzSettingsMapper.selectById(jqPlan.getGid());
                    jqPlan.setGidName(jqbzSettings.getName());
                }
                if ("2".equals(jqPlan.getGxType())){
                    JqzzSetting jqzzSetting = jqzzSettingMapper.selectById(jqPlan.getGid());
                    jqPlan.setGidName(jqzzSetting.getName());
                }
                if ("3".equals(jqPlan.getGxType())){
                    JqcsSetting jqcsSetting = jqcsSettingMapper.selectById(jqPlan.getGid());
                    jqPlan.setGidName(jqcsSetting.getName());
                }
                if ("4".equals(jqPlan.getGxType())){
                    JqfzSetting jqfzSetting = jqfzSettingMapper.selectById(jqPlan.getGid());
                    jqPlan.setGidName(jqfzSetting.getName());
                }
                if ("5".equals(jqPlan.getGxType())){
                    JqdbSettings jqdbSettings = jqdbSettingsMapper.selectById(jqPlan.getGid());
                    jqPlan.setGidName(jqdbSettings.getName());
                }
            }
        }
        page.setTotal(super.selectCount(wrapper));

        return page;
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean approve(Integer id, Token token) throws AdscmSystemException {
        //查询到这条记录
        JqPlan jqPlan = super.selectById(id);
        if (AdscmBaseUtils.getInstance().isNotEmpty(jqPlan,null)){
           if (!AdscmBaseUtils.getInstance().isNotEmpty(jqPlan.getPerfromer(),null)){
               throw new AdscmSystemException("未填写工序执行人");
           }
           if (!AdscmBaseUtils.getInstance().isNotEmpty(jqPlan.getStartTime(),null)){
               throw new AdscmSystemException("计划完成时间没得");
           }
           if ("1".equals(jqPlan.getGxType())){
               //部装
               JqbzPartsassembly jqbzPartsassembly=new JqbzPartsassembly();
               //工序id
               jqbzPartsassembly.setResourcename(jqPlan.getGid().toString());
               //工序执行人
               jqbzPartsassembly.setTaskperformperson(jqPlan.getPerfromer());
               jqbzPartsassembly.setTaskstartorendtime(jqPlan.getStartTime());
               jqbzPartsassembly.setTaskreleaseperson(token.getUser().getId().toString());
               jqbzPartsassembly.setTaskreleaseaddtime(new Date());
               jqbzPartsassembly.setTaskfinishstate(0);
               jqbzPartsassembly.setTaskstate(0);
               jqbzPartsassembly.setIstaskstart("0");
               jqbzPartsassembly.setIstaskbegin("0");
               jqbzPartsassembly.setIstaskend("0");
               jqbzPartsassembly.setIsreviewtask("0");
               jqbzPartsassembly.setReviewresult("-1");
               jqbzPartsassemblyService.insertJqbzPartsassembly(jqbzPartsassembly);
           }
            //总装
           if ("2".equals(jqPlan.getGxType())){
               //根据工序号查询工序的
               JqzzSetting jqzzSetting = jqzzSettingMapper.selectById(jqPlan.getGid());
               //根据机器类型查询机器编码
               JyDrawingType jyDrawingType = jyDrawingTypeMapper.selectById(jqzzSetting.getType());
               //之前使用的完成日期，修改成 6位批号
              // String yearMonth = new SimpleDateFormat("yyMMdd").format(jqPlan.getStartTime());
               String yearMonth ="";
               if (AdscmBaseUtils.getInstance().isNotEmpty(jqPlan.getBatch(),null)){
                   yearMonth  = jqPlan.getBatch();
               } else {
                   throw  new  AdscmSystemException("批号不存在");
               }

               //先查询是否同机器总装已经生成了机器编号
               String  macCode="";//机器编号
               Wrapper<JqPlan> jqPlanWrapper=new EntityWrapper<>();
               jqPlanWrapper.eq("macNo",jqPlan.getMacNo());
               jqPlanWrapper.eq("gxType",2);
               jqPlanWrapper.isNotNull("macCode");
               List<JqPlan> jqPlans = super.selectList(jqPlanWrapper);
               if (jqPlans!=null &&jqPlans.size()>0){
                   macCode= jqPlans.get(0).getMacCode();
               }else {
                   //查询数据最大的机器编号
                   String maccode = jyDrawingType.getCode();

                   Wrapper<JqzzMachine>  wrapper=new EntityWrapper<>();
                   wrapper.like("TASKCODE", maccode + yearMonth, SqlLike.RIGHT);
                   wrapper.orderBy("TASKCODE",false);
                   List<JqzzMachine> jqzzMachines = jqzzMachineMapper.selectList(wrapper);
                   if (jqzzMachines.size()>0){
                       JqzzMachine oldjqzzMachine = jqzzMachines.get(0);
                       String oldCode = oldjqzzMachine.getTaskcode();
                       long tempCode=Long.valueOf(oldCode.replace(maccode,""))+1;
                       macCode=maccode+String.valueOf(tempCode);
                   }else {
                       macCode=maccode+yearMonth+"01";
                   }
               }
               JqzzMachine  jqzzMachine=new JqzzMachine();

               jqzzMachine.setTaskperformperson(jqPlan.getPerfromer());
               jqzzMachine.setTaskreleaseaddtime(new Date());
               jqzzMachine.setTaskfinishstate(0);
               jqzzMachine.setTaskstate(0);
               jqzzMachine.setIstaskstart("0");
               jqzzMachine.setIstaskbegin("0");
               jqzzMachine.setIstaskend("0");
               jqzzMachine.setIsreviewtask("0");
               jqzzMachine.setReviewresult("0");
               jqzzMachine.setResourcename(jqzzSetting.getId().toString());
               jqzzMachine.setTaskcode(macCode);
               jqzzMachine.setTaskstartorendtime(jqPlan.getStartTime());
               jqzzMachine.setTaskreleaseperson(token.getUser().getId().toString());
               jqzzMachine.setBatchnums(yearMonth);
               jqzzMachineMapper.insert(jqzzMachine);

               //根据配置拿到他的零件物料输入列表
               Wrapper<JqzzSettingInput> getInputWrapper=new EntityWrapper<>();
               getInputWrapper.eq("pid",jqzzSetting.getId());
               List<JqzzSettingInput> jqzzSettingInputs = jqzzSettingInputMapper.selectList(getInputWrapper);
               for (JqzzSettingInput jqzzSettingInput : jqzzSettingInputs) {
                   JqzzMaterial jqzzMaterial=new JqzzMaterial();
                   CgMaterial cgMaterial = cgMaterialMapper.selectById(jqzzSettingInput.getCid());
                   jqzzMaterial.setTid(jqzzMachine.getTid());
                   jqzzMaterial.setName(jqzzSettingInput.getCid().toString());
                   jqzzMaterial.setCode(cgMaterial.getCode());
                   jqzzMaterial.setType(cgMaterial.getType());
                   jqzzMaterial.setIsAssembly(0);
                   jqzzMaterial.setNum(jqzzSettingInput.getNum());
                   jqzzMaterialMapper.insert(jqzzMaterial);
               }
               //创建部件的输入列表
               Wrapper<JqzzSettingParts> jqzzSettingPartsWrapper=new EntityWrapper<>();
               jqzzSettingPartsWrapper.eq("pid",jqzzSetting.getId());
               List<JqzzSettingParts> jqzzSettingParts = jqzzSettingPartsMapper.selectList(jqzzSettingPartsWrapper);
               for (JqzzSettingParts jqzzSettingPart : jqzzSettingParts) {
                   JqzzPartsMaterial  jqzzPartsMaterial =new JqzzPartsMaterial();
                   JqbzSettings jqbzSettings = jqbzSettingsMapper.selectById(jqzzSettingPart.getCid());
                   jqzzPartsMaterial.setTid(jqzzMachine.getTid());
                   jqzzPartsMaterial.setName(jqzzSettingPart.getCid().toString());
                   jqzzPartsMaterial.setType(jqbzSettings.getType());
                   jqzzPartsMaterial.setCode(jqbzSettings.getCode());
                   jqzzPartsMaterial.setIsAssembly(0);
                   jqzzPartsMaterial.setNum(jqzzSettingPart.getNum());
                   jqzzPartsMaterialMapper.insert(jqzzPartsMaterial);
               }
               //装配过程记录
               Wrapper<JqzzSettingProcess> jqzzSettingProcessWrapper =new EntityWrapper<>();
               jqzzSettingProcessWrapper.eq("pid",jqzzSetting.getId());
               List<JqzzSettingProcess> jqzzSettingProcesses = jqzzSettingProcessMapper.selectList(jqzzSettingProcessWrapper);
               for (JqzzSettingProcess jqzzSettingProcess : jqzzSettingProcesses) {
                   JqzzAssembly jqzzAssembly =new JqzzAssembly();
                   jqzzAssembly.setPid(jqzzMachine.getTid());
                   jqzzAssembly.setCid(jqzzSettingProcess.getId());
                   jqzzAssembly.setName(jqzzSettingProcess.getName());
                   jqzzAssembly.setReference(jqzzSettingProcess.getReference());
                   jqzzAssembly.setUnit(jqzzSettingProcess.getUnit());
                   jqzzAssembly.setType(jqzzSettingProcess.getType());
                   jqzzAssembly.setRank(jqzzSettingProcess.getRank());
                   jqzzAssembly.setRemark(jqzzSettingProcess.getRemark());
                   jqzzAssemblyMapper.insert(jqzzAssembly);
               }
               jqPlan.setMacCode(jqzzMachine.getTaskcode());
           }
           //测试
            if ("3".equals(jqPlan.getGxType())){
             //查询同一机器编号的
                String  macCode="";//机器编号
                Wrapper<JqPlan> jqPlanWrapper=new EntityWrapper<>();
                jqPlanWrapper.eq("macNo",jqPlan.getMacNo());
                jqPlanWrapper.eq("gxType",2);
                jqPlanWrapper.isNotNull("macCode");
                List<JqPlan> jqPlans = super.selectList(jqPlanWrapper);
                if (jqPlans!=null &&jqPlans.size()>0){
                    JqPlan macNo = jqPlans.get(0);
                    JqcsMachineTest jqcsMachineTest=new JqcsMachineTest();
                    jqcsMachineTest.setResourcename(macNo.getMacCode());
                    jqcsMachineTest.setTaskreleaseperson(token.getUser().getId().toString());
                    jqcsMachineTest.setTaskperformperson(jqPlan.getPerfromer());
                    jqcsMachineTestService.insertJqcsMachineTest(jqcsMachineTest);
                }else {
                    throw new AdscmSystemException("请先审核完成总装任务");
                }
            }
            //发证
            if ("4".equals(jqPlan.getGxType())){
                String  macCode="";//机器编号
                Wrapper<JqPlan> jqPlanWrapper=new EntityWrapper<>();
                jqPlanWrapper.eq("macNo",jqPlan.getMacNo());
                jqPlanWrapper.eq("gxType",2);
                jqPlanWrapper.isNotNull("macCode");
                List<JqPlan> jqPlans = super.selectList(jqPlanWrapper);
                if (jqPlans!=null &&jqPlans.size()>0){
                    JqPlan macNo = jqPlans.get(0);
                    JqfzIssueQs jqfzIssueQs=new JqfzIssueQs();
                    jqfzIssueQs.setResourcename(macNo.getMacCode());
                    jqfzIssueQs.setTaskreleaseperson(token.getUser().getId().toString());
                    jqfzIssueQs.setTaskperformperson(jqPlan.getPerfromer());

                    jqfzIssueQsService.insertJqfzIssueQs(jqfzIssueQs);
                }else {
                    throw new AdscmSystemException("请先审核完成总装任务");
                }
            }
            //打包
            if ("4".equals(jqPlan.getGxType())){
                String  macCode="";//机器编号
                Wrapper<JqPlan> jqPlanWrapper=new EntityWrapper<>();
                jqPlanWrapper.eq("macNo",jqPlan.getMacNo());
                jqPlanWrapper.eq("gxType",2);
                jqPlanWrapper.isNotNull("macCode");
                List<JqPlan> jqPlans = super.selectList(jqPlanWrapper);
                if (jqPlans!=null &&jqPlans.size()>0){
                    JqPlan macNo = jqPlans.get(0);
                    //打包
                    JqdbMachinepacking jqdbMachinepacking =new JqdbMachinepacking();
                    jqdbMachinepacking.setResourcename(macNo.getMacCode());
                    jqdbMachinepacking.setTaskreleaseperson(token.getUser().getId().toString());
                    jqdbMachinepacking.setTaskperformperson(jqPlan.getPerfromer());
                    jqdbMachinepackingService.insertJqdbMachinepacking(jqdbMachinepacking);
                }else {
                    throw new AdscmSystemException("请先审核完成总装任务");
                }
            }

            jqPlan.setState(1);
        super.updateById(jqPlan);
        }else {
            throw  new AdscmSystemException("未找到该记录");
        }

        return false;
    }

    @Override
    public boolean insertJqPlan(QueryJqPlan queryJqPlan,Token token)throws AdscmSystemException {
     //次数遍历
        Integer macNums = queryJqPlan.getMacNums();
          if (macNums<0){
              throw  new AdscmSystemException("生产数大于0");
          }
        for (int i = 0; i <macNums; i++) {
            //这个机型的部装查询部装工序
            Wrapper<JqbzSettings> jqbzSettingsWrapper=new EntityWrapper<>();
            jqbzSettingsWrapper.eq("type",queryJqPlan.getMacType());
            List<JqbzSettings> jqbzSettings = jqbzSettingsMapper.selectList(jqbzSettingsWrapper);
            for (JqbzSettings jqbzSetting : jqbzSettings) {
                for (int j = 0; j < jqbzSetting.getNums(); j++) {
                    JqbzPartsassembly jqbzPartsassembly=new JqbzPartsassembly();
                    jqbzPartsassembly.setResourcename(jqbzSetting.getId().toString());
                    jqbzPartsassembly.setTaskreleaseperson(token.getUser().getId().toString());
                    jqbzPartsassembly.setTaskreleaseaddtime(new Date());
                    jqbzPartsassembly.setTaskfinishstate(0);
                    jqbzPartsassembly.setTaskstate(0);
                    jqbzPartsassembly.setIstaskstart("0");
                    jqbzPartsassembly.setIstaskbegin("0");
                    jqbzPartsassembly.setIstaskend("0");
                    jqbzPartsassembly.setIsreviewtask("0");
                    jqbzPartsassembly.setReviewresult("-1");
                    jqbzPartsassembly.setTaskstartorendtime(queryJqPlan.getDate());
                    jqbzPartsassemblyService.insertJqbzPartsassembly(jqbzPartsassembly);
                }
            }
            //总装生成
            JqzzMachine jqzzMachine =new JqzzMachine();
            jqzzMachine.setResourcename(queryJqPlan.getMacType().toString());
            jqzzMachine.setTaskreleaseperson(token.getUser().getId().toString());
            jqzzMachine.setTaskreleaseaddtime(new Date());
            jqzzMachine.setTaskfinishstate(0);
            jqzzMachine.setTaskstate(0);
            jqzzMachine.setIstaskstart("0");
            jqzzMachine.setIstaskbegin("0");
            jqzzMachine.setIstaskend("0");
            jqzzMachine.setIsreviewtask("0");
            jqzzMachine.setReviewresult("0");
            jqzzMachine.setTaskstartorendtime(queryJqPlan.getDate());
           String code= jqzzMachineService.insertJqzzMachine(jqzzMachine);
            //测试
              JqcsMachineTest jqcsMachineTest=new JqcsMachineTest();
            jqcsMachineTest.setResourcename(code);
                jqcsMachineTestService.insertJqcsMachineTest(jqcsMachineTest);
            //发证
            JqfzIssueQs jqfzIssueQs=new JqfzIssueQs();
            jqfzIssueQs.setResourcename(code);

            jqfzIssueQsService.insertJqfzIssueQs(jqfzIssueQs);
             //打包
            JqdbMachinepacking jqdbMachinepacking =new JqdbMachinepacking();
            jqdbMachinepacking.setResourcename(code);
            jqdbMachinepackingService.insertJqdbMachinepacking(jqdbMachinepacking);
        }
        return false;
    }

    @Override
    public boolean insertJqPlanByPlan(QueryCondition queryCondition, Token token) throws AdscmSystemException{
        //首先根据条件查询工序计划
        String batch = queryCondition.getBatch();
        PlanResult planResult = machineProcessService.selectMac(queryCondition);
        List<MachineProcess> result = planResult.getResult();
         //遍历这个查询结果装入一个
        HashMap<String,MachineProcess> map =new HashMap<>();
        for (MachineProcess machineProcess : result) {
            map.put(machineProcess.getName(),machineProcess);
        }
        //根据机器数量遍历
        for (int i = 0; i < queryCondition.getMacNums(); i++) {
            //先确定机器编号macNo
            String yearmonth=new SimpleDateFormat("yyMMdd").format(new Date());
            Wrapper<JqPlan> jqPlanWrapper=new EntityWrapper<>();
            jqPlanWrapper.like("macNo",yearmonth, SqlLike.RIGHT);
            jqPlanWrapper.orderBy("macNo",false);
            jqPlanWrapper.last("limit 1");
            List<JqPlan> jqPlans = super.selectList(jqPlanWrapper);
            String macNo="";
            if (jqPlans!=null&&jqPlans.size()>0){
                JqPlan jqPlan = jqPlans.get(0);
                macNo= String.valueOf(Integer.valueOf(jqPlan.getMacNo())+1)   ;
            }else {
                macNo=yearmonth+"01";
            }

            //查询部装工序
            Wrapper<JqbzSettings> jqbzSettingsWrapper=new EntityWrapper<>();
            jqbzSettingsWrapper.eq("type",queryCondition.getMacType());
            List<JqbzSettings> jqbzSettings = jqbzSettingsMapper.selectList(jqbzSettingsWrapper);
            for (JqbzSettings jqbzSetting : jqbzSettings) {
                MachineProcess machineProcess = map.get(jqbzSetting.getName());
                Integer nums = jqbzSetting.getNums();
                for (int j = 0; j <nums; j++) {
                    JqPlan jqPlan =new JqPlan();
                    jqPlan.setMakeNo(queryCondition.getMakeNo());
                    jqPlan.setMacNo(macNo);
                    if (AdscmBaseUtils.getInstance().isNotEmpty(jqbzSetting.getPerformer(),null)){
                        jqPlan.setPerfromer(jqbzSetting.getPerformer());
                    }
                    jqPlan.setGxName(jqbzSetting.getName());
                    jqPlan.setGid(jqbzSetting.getId());
                    if (AdscmBaseUtils.getInstance().isNotEmpty(machineProcess,null)){
                        jqPlan.setStartTime(machineProcess.getStartTime());
                    }

                    jqPlan.setGxType("1");
                    jqPlan.setState(0);
                    jqPlan.setCreateTime(new Date());
                    if (AdscmBaseUtils.getInstance().isNotEmpty(token,null)){
                        jqPlan.setCreator(token.getUser().getId().toString());
                    }
                    jqPlan.setPerfromer(queryCondition.getPerformer().toString());
                    jqPlan.setBatch(batch);
                    super.insert(jqPlan);
                }
            }
         //总装任务
            Wrapper<JqzzSetting> jqzzSettingWrapper=new EntityWrapper<>();
            jqzzSettingWrapper.eq("type",queryCondition.getMacType());
            List<JqzzSetting> jqzzSettings = jqzzSettingMapper.selectList(jqzzSettingWrapper);
            for (JqzzSetting jqzzSetting : jqzzSettings) {
                MachineProcess machineProcess = map.get(jqzzSetting.getName());
                Integer nums = jqzzSetting.getNums();
                for (int k = 0; k <nums; k++) {
                    JqPlan jqPlan =new JqPlan();
                    jqPlan.setMakeNo(queryCondition.getMakeNo());
                    jqPlan.setMacNo(macNo);
                    if (AdscmBaseUtils.getInstance().isNotEmpty(jqzzSetting.getPerformer(),null)){
                        jqPlan.setPerfromer(jqzzSetting.getPerformer());
                    }
                    jqPlan.setGxName(jqzzSetting.getName());
                    jqPlan.setGid(jqzzSetting.getId());
                    if (AdscmBaseUtils.getInstance().isNotEmpty(machineProcess,null)){
                        jqPlan.setStartTime(machineProcess.getStartTime());
                    }
                    jqPlan.setGxType("2");
                    jqPlan.setState(0);
                    jqPlan.setCreateTime(new Date());
                    if (AdscmBaseUtils.getInstance().isNotEmpty(token,null)){
                        jqPlan.setCreator(token.getUser().getId().toString());
                    }
                    jqPlan.setPerfromer(queryCondition.getPerformer().toString());
                    jqPlan.setBatch(batch);
                    super.insert(jqPlan);
                }
            }
            //测试
            Wrapper<JqcsSetting> jqcsSettingWrapper=new EntityWrapper<>();
            jqcsSettingWrapper.eq("type",queryCondition.getMacType());
            List<JqcsSetting> jqcsSettings = jqcsSettingMapper.selectList(jqcsSettingWrapper);
            for (JqcsSetting jqcsSetting : jqcsSettings) {
                MachineProcess machineProcess = map.get(jqcsSetting.getName());
                JqPlan jqPlan =new JqPlan();
                jqPlan.setMacNo(macNo);
                jqPlan.setGxName(jqcsSetting.getName());
                jqPlan.setMakeNo(queryCondition.getMakeNo());
                jqPlan.setGid(jqcsSetting.getId());
                if (AdscmBaseUtils.getInstance().isNotEmpty(machineProcess,null)){
                    jqPlan.setStartTime(machineProcess.getStartTime());
                }
                jqPlan.setGxType("3");
                jqPlan.setState(0);
                jqPlan.setCreateTime(new Date());
                if (AdscmBaseUtils.getInstance().isNotEmpty(token,null)){
                    jqPlan.setCreator(token.getUser().getId().toString());
                }
                jqPlan.setPerfromer(queryCondition.getPerformer().toString());
                jqPlan.setBatch(batch);
                super.insert(jqPlan);
            }
            //发证
            Wrapper<JqfzSetting> jqfzSettingWrapper =new EntityWrapper<>();
            jqfzSettingWrapper.eq("type",queryCondition.getMacType());
            List<JqfzSetting> jqfzSettings = jqfzSettingMapper.selectList(jqfzSettingWrapper);
            for (JqfzSetting jqfzSetting : jqfzSettings) {
                MachineProcess machineProcess = map.get(jqfzSetting.getName());
                JqPlan jqPlan =new JqPlan();
                jqPlan.setMacNo(macNo);
                jqPlan.setGxName(jqfzSetting.getName());
                jqPlan.setMakeNo(queryCondition.getMakeNo());
                jqPlan.setGid(jqfzSetting.getId());
                if (AdscmBaseUtils.getInstance().isNotEmpty(machineProcess,null)){
                    jqPlan.setStartTime(machineProcess.getStartTime());
                }
                jqPlan.setGxType("4");
                jqPlan.setState(0);
                jqPlan.setCreateTime(new Date());
                if (AdscmBaseUtils.getInstance().isNotEmpty(token,null)){
                    jqPlan.setCreator(token.getUser().getId().toString());
                }
                jqPlan.setPerfromer(queryCondition.getPerformer().toString());
                jqPlan.setBatch(batch);
                super.insert(jqPlan);
            }
            //打包
            Wrapper<JqdbSettings> jqdbSettingsWrapper=new EntityWrapper<>();
            jqdbSettingsWrapper.eq("type",queryCondition.getMacType());
            List<JqdbSettings> jqdbSettings = jqdbSettingsMapper.selectList(jqdbSettingsWrapper);
            for (JqdbSettings jqdbSetting : jqdbSettings) {
                MachineProcess machineProcess = map.get(jqdbSetting.getName());
                JqPlan jqPlan =new JqPlan();
                jqPlan.setMacNo(macNo);
                jqPlan.setMakeNo(queryCondition.getMakeNo());
                jqPlan.setGid(jqdbSetting.getId());
                if (AdscmBaseUtils.getInstance().isNotEmpty(machineProcess,null)){
                    jqPlan.setStartTime(machineProcess.getStartTime());
                }
                jqPlan.setGxType("5");
                jqPlan.setState(0);
                jqPlan.setCreateTime(new Date());
                if (AdscmBaseUtils.getInstance().isNotEmpty(token,null)){
                    jqPlan.setCreator(token.getUser().getId().toString());
                }
                jqPlan.setPerfromer(queryCondition.getPerformer().toString());
                jqPlan.setBatch(batch);
                super.insert(jqPlan);
            }
        }

        return false;
    }

    @Override
    public boolean approves(List<Integer> ids, Token token) throws AdscmSystemException{
        for (Integer id : ids) {
            approve(id,token);
        }
        return true;
    }
}
